<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/9/5
 * Time: 16:08
 */
namespace app\admin\controller;
use think\Db;
class Evaluate extends Base {
    public function index(){
        if(request()->isAjax ()){
            extract(input());
            $where = [];
            if(isset($user_name) && $user_name != ''){
                $where['uuu.user_username'] = ['like', '%' . $user_name . '%'];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('evaluate')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.evaluate_teacher_id','left')
                ->join('up_u_user uuu1','uuu1.user_id = a.evaluate_user_id','left')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('evaluate')->alias('a')
                ->join('up_u_user uuu','uuu.user_id = a.evaluate_teacher_id','left')
                ->join('up_u_user uuu1','uuu1.user_id = a.evaluate_user_id','left')
                ->where($where)
                ->page($Nowpage,$limits)
                ->field('a.*,uuu.user_username,uuu1.user_username as username')
                ->order('evaluate_time desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }

    //详情
    public function detail(){
        $id = input('param.id');
        $where['evaluate_id'] = $id;
        $res = Db::name('evaluate')->alias('a')
            ->join('up_u_user uuu','uuu.user_id = a.evaluate_teacher_id','left')
            ->join('up_u_user uuu1','uuu1.user_id = a.evaluate_user_id','left')
            ->where($where)
            ->field('a.*,uuu.user_username,uuu1.user_username as username')
            ->find();
        $this->assign('res',$res);
        return $this->fetch();
    }
}